
using QdbUnit;
using Qdb;
using Qdb.Config;
using Qdb.Ext;
using Qdb.Tests.Common.Exceptions;

namespace Qdb.Tests.Common.Exceptions
{
	public class QdbIOExceptionTestCase : QdbIOExceptionTestCaseBase
	{
		public static void Main(string[] args)
		{
			new QdbIOExceptionTestCase().RunSolo();
		}

		protected override void Configure(IConfiguration config)
		{
			base.Configure(config);
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestActivate()
		{
			Store(new QdbIOExceptionTestCase.Item(3));
			Fixture().Config().ActivationDepth(1);
			Fixture().Reopen(this);
			QdbIOExceptionTestCase.Item item = (QdbIOExceptionTestCase.Item)((QdbIOExceptionTestCase.Item
				)RetrieveOnlyInstance(typeof(QdbIOExceptionTestCase.Item)));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_25(this, item));
		}

		private sealed class _ICodeBlock_25 : ICodeBlock
		{
			public _ICodeBlock_25(QdbIOExceptionTestCase _enclosing, QdbIOExceptionTestCase.Item
				 item)
			{
				this._enclosing = _enclosing;
				this.item = item;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Activate(item, 3);
			}

			private readonly QdbIOExceptionTestCase _enclosing;

			private readonly QdbIOExceptionTestCase.Item item;
		}

		public virtual void TestClose()
		{
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_34(this));
		}

		private sealed class _ICodeBlock_34 : ICodeBlock
		{
			public _ICodeBlock_34(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Close();
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		public virtual void TestCommit()
		{
			Store(new QdbIOExceptionTestCase.Item(0));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_44(this));
		}

		private sealed class _ICodeBlock_44 : ICodeBlock
		{
			public _ICodeBlock_44(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Commit();
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestDelete()
		{
			Store(new QdbIOExceptionTestCase.Item(3));
			QdbIOExceptionTestCase.Item item = (QdbIOExceptionTestCase.Item)((QdbIOExceptionTestCase.Item
				)RetrieveOnlyInstance(typeof(QdbIOExceptionTestCase.Item)));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_55(this, item));
		}

		private sealed class _ICodeBlock_55 : ICodeBlock
		{
			public _ICodeBlock_55(QdbIOExceptionTestCase _enclosing, QdbIOExceptionTestCase.Item
				 item)
			{
				this._enclosing = _enclosing;
				this.item = item;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Delete(item);
			}

			private readonly QdbIOExceptionTestCase _enclosing;

			private readonly QdbIOExceptionTestCase.Item item;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestGet()
		{
			Store(new QdbIOExceptionTestCase.Item(3));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_65(this));
		}

		private sealed class _ICodeBlock_65 : ICodeBlock
		{
			public _ICodeBlock_65(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().QueryByExample(typeof(QdbIOExceptionTestCase.Item));
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestGetAll()
		{
			Store(new QdbIOExceptionTestCase.Item(3));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_75(this));
		}

		private sealed class _ICodeBlock_75 : ICodeBlock
		{
			public _ICodeBlock_75(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				IObjectSet os = this._enclosing.Db().QueryByExample(null);
				while (os.HasNext())
				{
					os.Next();
				}
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestQuery()
		{
			Store(new QdbIOExceptionTestCase.Item(3));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_88(this));
		}

		private sealed class _ICodeBlock_88 : ICodeBlock
		{
			public _ICodeBlock_88(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Query(typeof(QdbIOExceptionTestCase.Item));
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestRollback()
		{
			Store(new QdbIOExceptionTestCase.Item(3));
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_98(this));
		}

		private sealed class _ICodeBlock_98 : ICodeBlock
		{
			public _ICodeBlock_98(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Rollback();
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestSet()
		{
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_107(this));
		}

		private sealed class _ICodeBlock_107 : ICodeBlock
		{
			public _ICodeBlock_107(QdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Store(new QdbIOExceptionTestCase.Item(3));
			}

			private readonly QdbIOExceptionTestCase _enclosing;
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestGetByUUID()
		{
			Fixture().Config().GenerateUUIDs(ConfigScope.Globally);
			Fixture().Reopen(this);
			QdbIOExceptionTestCase.Item item = new QdbIOExceptionTestCase.Item(1);
			Store(item);
			QdbUUID uuid = Db().GetObjectInfo(item).GetUUID();
			Fixture().Reopen(this);
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_122(this, uuid));
		}

		private sealed class _ICodeBlock_122 : ICodeBlock
		{
			public _ICodeBlock_122(QdbIOExceptionTestCase _enclosing, QdbUUID uuid)
			{
				this._enclosing = _enclosing;
				this.uuid = uuid;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().GetByUUID(uuid);
			}

			private readonly QdbIOExceptionTestCase _enclosing;

			private readonly QdbUUID uuid;
		}

		public class Item
		{
			public Item(int depth)
			{
				member = new QdbIOExceptionTestCase.DeepMemeber(depth);
			}

			public QdbIOExceptionTestCase.DeepMemeber member;
		}

		public class DeepMemeber
		{
			public DeepMemeber(int depth)
			{
				if (depth > 0)
				{
					member = new QdbIOExceptionTestCase.DeepMemeber(--depth);
				}
			}

			public QdbIOExceptionTestCase.DeepMemeber member;
		}
	}
}
